<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代理商列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
     .box a{
        margin-bottom:10px;
     }       
     .name{
        cursor: pointer;
     }
     .cengji{
        line-height: 36px;
     }
     #demo li{
        width:300px;
     }
     .eyes{
        margin-left: 25px;
        width: 20px;
        height: 7px;
        margin-top: 8px
     }
     .xgrate{
        color: #fff;
        font-size: 15px;
        padding: 7px;
        height: 30px;
        line-height: 30px;
        background-color: #3475c3;
    }
    </style>
    
</head>
<body>
    <div class="layui-fluid" id="LAY-component-grid-mobile-pc">
        <div class="layui-row layui-col-space10" style="margin-top:0px">

        <div class="layui-row layui-col-space10">

            <div class="layui-col-xs4 layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header" style="display:flex;justify-content: space-between;">
                        <div style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">代理商列表</div>
                        <div class="layui-btn-container" style="font-size:14px;">
                            <a class="layui-btn layui-btn-primary" id="showAllAgent" style="background-color:#3475c3;border-radius: 5px;border:none;color:#fff;display: block;padding: 0 8px;margin-top:2px;display:none">显示全部</a>
                        </div>
                        <div style="display:flex;align-items: center;position:relative">
                            <input type="text" id="searchKey" placeholder="搜索" autocomplete="off" class="layui-input">
                            <button class="layui-btn layuiadmin-btn-list" style="border-radius:5px;margin-left: 4px;" id="searchBtn" style="margin-bottom: 0;height:36px;line-height: 36px;">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="right: 5px;margin-top: -9px;"></i>
                            </button>
                        </div>
                    </div>
                    <div class="layui-card-body" style="height:500px;overflow-y: auto;">
                        <div class="li_list" style="display: inline-block; width: 300px; padding: 10px;  overflow: auto;">
                           <ul id="demo"></ul>
                           <ul id="searchlist"></ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs6 layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">代理商详情</div>
                    <div class="layui-card-body" style="margin-top: 30px;">
                        <div class="cmdlist-container">
                            <img style='margin-top:-60px;' src="{{asset('/school/images/touxiang.png')}}">
                            <div class="xinxi" style="display: inline-block;">
                                <p  data-id=""><span class="name"></span>(<span class="userId"></span>) <span style="color:red;border:1px solid #ccc;padding:5px 10px;border-radius:5px" class="cz">初始化密码</span> </p>
                               <div style="display:flex;">
                               <p class="phone"> </p>
                               <div class='eyes'>
                                  <img id="eyes" style="height:8px;margin-top: -15px;" src="{{asset('/school/images/see-none.png')}}">
                                </div>
                               </div>
                                <p class="jine">赏金余额:<span></span></p>
                                <p class="settlement_money">服务费余额:<span></span></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs8 layui-col-md8">
                <div class="layui-card">
                    <div class="layui-card-header">功能管理</div>
                    <div class="layui-card-body">
                        <div class="cmdlist-container box">
                            <a class="layui-btn layui-btn-primary" style="border-radius: 5px;" lay-href="{{url('/user/addagent')}}" id="agent" data-id="">添加代理商</a>
                            <a class="layui-btn layui-btn-primary" style="border-radius: 5px;" id="role_fen" data-id="">角色分配</a>
                            <a class="layui-btn layui-btn-primary rate" style="border-radius: 5px;" id="rate" data-id="">支付成本费率管理</a>
                            <!--<a class="layui-btn layui-btn-primary server_rate" style="border-radius: 5px;" id="server_rate" data-id="">服务费成本费率管理</a>-->
                            <!-- <a class="layui-btn layui-btn-primary storerate" style="border-radius: 5px; margin-left:0px;" id="storerate" data-id="">商户默认费率</a> -->
                            <a class="layui-btn layui-btn-primary chaxun" style="border-radius: 5px;" id="chaxun" data-id="">对账查询</a>
                            <a class="layui-btn layui-btn-primary editmsg" style="border-radius: 5px;" id="editmsg" data-id="" data-username="" data-phone="" data-name="">修改信息</a>
                            <a class="layui-btn layui-btn-primary transfer" style="border-radius: 5px;" id="transfer"  data-id="" data-username="" >转移代理商</a>
                            <a class="layui-btn layui-btn-primary pingan" style="border-radius: 5px;" id="pingan" data-id="">平安标记</a>
                            <a class="layui-btn layui-btn-primary pass_permission" style="border-radius: 5px;" data-id="">新增密钥</a>
                            
                            <a class="layui-btn layui-btn-primary sign_manage" style="border-radius: 5px;" data-id="">签约管理</a>
                            <a class="layui-btn layui-btn-primary pass_list" style="border-radius: 5px;" data-id="">密钥管理</a>
                            <a class="layui-btn layui-btn-primary" style="border-radius: 5px;" data-id="" href="https://pay.zgjindoufu.com/user/storelist">门店管理</a>
                            
                             <a class="layui-btn layui-btn-primary user_stores" style="border-radius: 5px;" id="user_stores" data-id="">渠道对账单</a>
                             <a class="layui-btn layui-btn-primary merchant_company" style="border-radius: 5px;" id="merchant_company" data-id="">商户通道对账单</a>
                             <a class="layui-btn layui-btn-primary agentincomworker" style="border-radius: 5px;" data-id="">员工管理</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs8 layui-col-md8 ceng">
                <div class="layui-card">
                    <div class="layui-card-header">代理层级搜索</div>
                    <div class="layui-card-body">
                        <div class="cmdlist-container">
                            <div class="layui-form" lay-filter="component-form-group" style="width:600px;display: inline-block;">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" style="border-radius:5px;" name="schoolname" placeholder="请输入代理名称或手机号" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <button class="layui-btn layuiadmin-btn-list" style="border-radius:5px;" lay-submit="" lay-filter="LAY-app-contlist-search" style="margin-bottom: 0;height:36px;line-height: 36px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                        </button>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block cengji" style='margin-left: 0px;'>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="user_qr" class="hide" style="display: none;background-color: #fff;position:absolute;left:1150px;top:200px">
        <div class="xgrate">预充收款码</div>
        <div class="layui-card-body" style="padding: 15px;">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div id="code"> </div>
                </div>
            </div>
        </div>
    </div>

<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script> 
<script type="text/javascript" src="{{asset('/school/js/jsencrypt.min.js')}}"></script>
<script src="{{asset('/layuiadmin/jquery.min.js')}}"></script>
<script src="{{asset('/layuiadmin/jquerysession.js')}}"></script>
<script src="{{asset('/layuiadmin/layui/jquery.qrcode.min.js')}}"></script>
<script>
    var token = localStorage.getItem("Usertoken");
    var level = localStorage.getItem("level");
    var treeData = [];

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        formSelects: 'formSelects'
    }).use(['index', 'form','tree'], function(){
        var $ = layui.$ 
            ,admin = layui.admin
            ,element = layui.tree
            ,form = layui.form;

        // 未登录,跳转登录页面
        $(document).ready(function(){
            if(token==null || token==''){
                window.location.href="{{url('/user/login')}}"; 
            }
        });

        var permissions = localStorage.getItem("permissions");
        var str=JSON.parse(permissions);
        var arr=[];
        for(var i=0;i<str.length;i++){
            var aa=str[i].name;
            arr.push(aa);
        }
        // console.log(arr)

        if(level != 0){
            // 权限管理+++++++++++++
            $('.box a').each(function(index,item){
            });
            $('.box a').each(function(index,item){
                if($.inArray($(this).html(),arr)==-1){
                    $(this).hide();
                }
            });
        }

        $.post("{{url('/api/user/get_sub_users')}}",
        {
            token:token
            ,return_type:'layui'
        },function(res){
        //    console.log(res);
            $('.name').html(res.data[0].name);
            $('.phone').html(res.data[0].phone);
            $('.jhm span').html(res.data[0].s_code);
            $('.jine span').html(res.data[0].money);
            $('.settlement_money span').html(res.data[0].settlement_money);
            $('#agent').attr('data-id',res.data[0].id);
            $('#role_fen').attr('data-id',res.data[0].id);
            $('#rate').attr('data-id',res.data[0].id);
            $('#server_rate').attr('data-id',res.data[0].id);
            $('#reward').attr('data-id',res.data[0].id);
            $('#putforward').attr('data-id',res.data[0].id);
            $('#storerate').attr('data-id',res.data[0].id);
            $('#storeconfig').attr('data-id',res.data[0].id);
            $('#chaxun').attr('data-id',res.data[0].id);
            $('#settle').attr('data-id',res.data[0].id);
            $('#flowerfq').attr('data-id',res.data[0].id);
            $('.name').attr('data-id',res.data[0].id);
            $('.userId').html(res.data[0].id);

            $('.editmsg').attr('data-id',res.data[0].id);
            $('.editmsg').attr('data-username',res.data[0].name);
            $('.editmsg').attr('data-phone',res.data[0].phone);
            $('.editmsg').attr('data-name',res.data[0].logo);

            $('#transfer').attr('data-id',res.data[0].id);
            $('#transfer').attr('data-username',res.data[0].name);
            $('.agentincomworker').attr('data-id',res.data[0].id);
            
            treeData = res.data;
            layui.tree({
                elem: '#demo'
                ,nodes: res.data
                ,click: function(node){
                               console.log(node); //node即为当前点击的节点数据
                    $('.name').html(node.name);
                    $('.phone').html(node.phone);
                    $('.jhm span').html(node.s_code);
                    $('.jine span').html(node.money);
                    $('.settlement_money span').html(node.settlement_money);
                    $('#agent').attr('data-id',node.id);
                    $('#rate').attr('data-id',node.id);
                    $('#server_rate').attr('data-id',node.id);
                    $('#reward').attr('data-id',node.id);
                    $('#putforward').attr('data-id',node.id);
                    $('#role_fen').attr('data-id',node.id);
                    $('#storerate').attr('data-id',node.id);
                    $('#storeconfig').attr('data-id',node.id);
                    $('#chaxun').attr('data-id',node.id);
                    $('#settle').attr('data-id',node.id);
                    $('#flowerfq').attr('data-id',node.id);
                    $('.name').attr('data-id',node.id);
                    $('.cz').attr('data-id',node.id);
                    $('.userId').html(node.id);
                    $('.editmsg').attr('data-id',node.id);
                    $('.editmsg').attr('data-username',node.name);
//                    $('.editmsg').attr('data-levelname',node.level_name);
                    $('.editmsg').attr('data-phone',node.phone);
                    $('.editmsg').attr('data-name',node.logo);
                    $('#transfer').attr('data-id',node.id);
                    $('#transfer').attr('data-username',node.name);
                    $('#server').attr('data-id',node.id);
                    $('#server').attr('data-username',node.name);
                    
                    $('.pass_permission').attr('data-id', node.id);
                    $('.agentincomworker').attr('data-id', node.id);
                
                }
            });

            var pid = parseInt(res.data[0].pid);

            if(pid < 2){
                $('.ceng').show()
            }else{
                $('.ceng').hide()
            }

        },"json");
        
        // 新增密钥
        $(".pass_permission").click(function(){
            // var pass = $("#pass_add").val();
            // // console.log(pass)

            // $.post("{{url('/api/glow/add_pass')}}", {
            //     token: token,
            //     pass: pass
            // }, function(res){
            //     // console.log( JSON.stringify(res) )
            //     if(res.status == 1){
            //         // console.log(1)
            
                    // 重置cookie有效期
                    var time = Date.parse(new Date()) + (5 * 60 * 1000);
                    $.session.set('time', time);
                    
                    // console.log( time )
            
                    var url = "{{url('/user/pass_permission?')}}";
                    top.layui.index.openTabsPage(url, '新增密钥');
            //     }else{
            //         // console.log(2)
            //         layer.msg(res.message, {
            //             offset: '50px',
            //             icon: 2,
            //             time: 3000
            //         });
            //     }
            // }, "json");
        });
        
        

        $(".eyes").click(function (){
            var _this = $(this);
            var proxyCompanyId = _this.parents(".xinxi").find(".userId").text();
            layer.prompt({title: '请输入密码', formType: 1}, function(pass, index){
                layer.close(index);
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4COVutRbOUfQNjvVOzwK49NzHIPRwwksnJ6QtdHwGmdUZiT2HZxVwfotcOjA5aY16D/2Ahq3gLH4yu2y42dS0lfeBMqUcm+bY7aZ54wClm75RI90uc54F8IgMkNz8J/VS9LYI/B4uHVsc+4KK4Ycr8S8O004ExtvQqu2QCl7Aai/WC4URIdCyNm8La2axoA1jjj3SzpytLvP6Z/iHSlx37Y9AMR0V94R13v4BFlMQDG+2REVJsk6LCyzHQfUvJlnsyKey0n/v8DLC070lQzLPYV0jsiit2AUkyURRLxEaZm2C0YYhfrGjl+x8n/kDteZbDVcyn7UsEdSicijv9DXkQIDAQAB");
                var data = encrypt.encrypt('pay_password='+pass);

                $.post("{{url('/api/user/check_platform_pay_password')}}",
                {
                  token:token,
                  sign:data
                },function(data){ 
                    if(data.status==1){                      
                      layer.close(index);
                      $.post("{{url('/api/user/user_info')}}",
                      {
                        token:token
                       ,user_id:proxyCompanyId
                      },function(data){
                          console.log(data)
                          $('.phone').html(data.data.phone)
                        //   if(data.status==1){
                        //     if(proxyCompanyId == 1){
                        //         $('.phone').html(data.data[0].phone)
                        //     }else{
                        //         var responseData = data.data[0].children;
                        //         responseData.forEach(function(item,index,arr){
                        //             if(item.id == proxyCompanyId) $('.phone').html(item.phone);
                        //         });
                        //     }
                            
                        //   }
                      },"json");
                    }else{
                      layer.msg(data.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                      });
                    }
                },"json");
              });
        });

        // 获取激活码
        $('.jhm').click(function(){
            localStorage.setItem('s_code', $(this).find('span').html());
            localStorage.setItem('s_agentname', $('.name').html());
        });
        $('#agent').click(function(){
            localStorage.setItem('agentname', $('.name').html());
            localStorage.setItem('dataid', $(this).attr('data-id'));
        });

        $("#role_fen").click(function(){
            var customer_id=$(this).attr('data-id');
            layer.open({
                type: 2,
                title: '角色分配',
                shade: false,
                maxmin: true,
                area: ['70%', '70%'],
                content: "{{url('/user/rolelist?')}}"+customer_id
            });
        });
        $("#rate").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.rate').attr('lay-href',"{{url('/user/ratelist?')}}"+user_id);
        });
        $("#user_stores").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.user_stores').attr('lay-href',"{{url('/user/user_stores?')}}"+user_id);
        });
        $("#merchant_company").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.merchant_company').attr('lay-href',"{{url('/user/merchant_company?')}}"+user_id);
        });
        $("#server_rate").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.server_rate').attr('lay-href',"{{url('/user/server_list?')}}"+user_id);
        });
        $("#storerate").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.storerate').attr('lay-href',"{{url('/user/storeratelist?')}}"+user_id);
        });
        $("#reward").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.reward').attr('lay-href',"{{url('/user/reward?')}}"+user_id);
        });
        $("#putforward").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.putforward').attr('lay-href',"{{url('/user/putforward?')}}"+user_id);
        });
        $("#storeconfig").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.storeconfig').attr('lay-href',"{{url('/user/storeconfig?')}}"+user_id);
        });
        $("#chaxun").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            var user_name=$('.name').html();
            $('.chaxun').attr('lay-href',"{{url('/user/reconciliation?user_id=')}}"+user_id+"&user_name="+user_name);
        });
        $("#pingan").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            var user_name=$('.name').html();
            $('.pingan').attr('lay-href',"{{url('/user/pingan?user_id=')}}"+user_id+"&user_name="+user_name);
        });
        // 签约管理
        $(".sign_manage").click(function(){
            top.layui.index.openTabsPage("{{url('/user/sign_manage?')}}", '签约管理');
        });
        // 密钥列表
        $(".pass_list").click(function(){
            top.layui.index.openTabsPage("{{url('/user/pass_list?')}}", '密钥管理');
        });
        // 密钥列表
        $(".chongzhi").click(function(){
            $.post("{{url('/api/user/user_qrpay')}}",
            {
                token:token
            },
            function(res){
                if(res.status==1){
                    $('#code').html('');
                    $('#code').qrcode(res.data.store_pay_qr);
                    $('#user_qr').show();
                }else if(res.status==2){
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                    });
                }
            },"json");
        });
        $("#settle").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.settle').attr('lay-href',"{{url('/user/settledetail?user_id=')}}"+user_id);
        });
        $("#flowerfq").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.flowerfq').attr('lay-href',"{{url('/user/flowerfq?user_id=')}}"+user_id);
        });
        $("#editmsg").click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.editmsg').attr('lay-href',"{{url('/user/editmsg?user_id=')}}"+user_id+"&user_name="+$(this).attr('data-username')+"&phone="+$(this).attr('data-phone')+"&logo="+$(this).attr('data-name'));
        });
        $('#transfer').click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.transfer').attr('lay-href',"{{url('/user/transferstore?user_id=')}}"+user_id+"&user_name="+$(this).attr('data-username'));
        });
        
        // 上月账单
        $('#lastbill').click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id = $(this).attr('data-id');
            $('.lastbill').attr('lay-href', "{{url('/user/lastbill')}}");
        });

        $(".server").dblclick(function(){
            var user_id=$(this).attr('data-id');
            layer.confirm('确认开通或取消代理服务费代扣吗？',{icon: 2}, function(index){
                $.post("{{url('/api/user/server_sub_user')}}",
                    {
                        token:token
                        ,user_id:user_id
                    },function(res){
                        if(res.status==1){
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 1
                                ,time: 2000
                            });
                        }else{
                            layer.msg(res.message, {
                                offset: '50px'
                                ,icon: 2
                                ,time: 3000
                            });
                        }
                    },"json");
            });
        });

        $(".name").dblclick(function(){
            var user_id=$(this).attr('data-id');
            layer.confirm('确认删除此消息?',{icon: 2}, function(index){
                $.post("{{url('/api/user/del_sub_user')}}",
                {
                    token:token
                    ,user_id:user_id
                },function(res){
                    //                  console.log(res);
                    if(res.status==1){
                        // obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        layer.close(index);
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 1
                            ,time: 2000
                        });
                    }else{
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 2
                            ,time: 3000
                        });
                    }
                },"json");
            });
        });
        
        $(".cz").dblclick(function(){
            var user_id=$(this).attr('data-id');
            layer.confirm('确定重置次代理商密码?',{icon: 2}, function(index){
                $.post("{{url('/api/user/cz_user_password')}}",
                {
                    token:token
                    ,user_id:user_id
                },function(res){
                    if(res.status==1){
                        layer.close(index);
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 1
                            ,time: 2000
                        });
                    }else{
                        layer.msg(res.message, {
                            offset: '50px'
                            ,icon: 2
                            ,time: 3000
                        });
                    }
                },"json");
            });
        });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var obj = data.field;
            var user_name = data.field.schoolname;
            $.post("{{url('/api/user/select_pid_user')}}",
            {
                token:token
                ,user_name:user_name
            },function(res){
                if(res.status==1){
                    html='';
                     for (var i = 0; i < res.data.info.length; i++) {
                        html += res.data.info[i]+'</br>';
                    }
                    $('.cengji').html(html)
                }else{
                    $('.cengji').html('');
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                    });
                }
            },"json");
        });
        
        // 代理商列表筛选
        $('#searchBtn').click(function(){
            var inputValue = $('#searchKey').val();
            console.log('您输入的内容是：' + inputValue);
            var resultData = mapTree(inputValue,treeData[0].children)
            console.log(resultData,'resultData-----')
            if(resultData.length>0){
                $('#searchlist').html('')
                $('.name').html(resultData[0].name);
                $('.phone').html(resultData[0].phone);
                $('.jhm span').html(resultData[0].s_code);
                $('.jine span').html(resultData[0].money);
                $('.settlement_money span').html(resultData[0].settlement_money);
                $('#agent').attr('data-id',resultData[0].id);
                $('#role_fen').attr('data-id',resultData[0].id);
                $('#rate').attr('data-id',resultData[0].id);
                $('#server_rate').attr('data-id',resultData[0].id);
                $('#reward').attr('data-id',resultData[0].id);
                $('#putforward').attr('data-id',resultData[0].id);
                $('#storerate').attr('data-id',resultData[0].id);
                $('#storeconfig').attr('data-id',resultData[0].id);
                $('#chaxun').attr('data-id',resultData[0].id);
                $('#settle').attr('data-id',resultData[0].id);
                $('#flowerfq').attr('data-id',resultData[0].id);
                $('.name').attr('data-id',resultData[0].id);
                $('.userId').html(resultData[0].id);

                $('.editmsg').attr('data-id',resultData[0].id);
                $('.editmsg').attr('data-username',resultData[0].name);
                $('.editmsg').attr('data-phone',resultData[0].phone);
                $('.editmsg').attr('data-name',resultData[0].logo);

                $('#transfer').attr('data-id',resultData[0].id);
                $('#transfer').attr('data-username',resultData[0].name);
                $('.agentincomworker').attr('data-id', resultData[0].id);
                $('#demo').hide()
                $('#showAllAgent').show();
                $('#searchlist').show();

                layui.tree({   
                elem: '#searchlist' // 指定元素
                ,nodes: resultData // 新数据

                ,click: function(node){
                console.log(node); //node即为当前点击的节点数据
                $('.name').html(node.name);
                $('.phone').html(node.phone);
                $('.jhm span').html(node.s_code);
                $('.jine span').html(node.money);
                $('.settlement_money span').html(node.settlement_money);
                $('#agent').attr('data-id',node.id);
                $('#rate').attr('data-id',node.id);
                $('#server_rate').attr('data-id',node.id);
                $('#reward').attr('data-id',node.id);
                $('#putforward').attr('data-id',node.id);
                $('#role_fen').attr('data-id',node.id);
                $('#storerate').attr('data-id',node.id);
                $('#storeconfig').attr('data-id',node.id);
                $('#chaxun').attr('data-id',node.id);
                $('#settle').attr('data-id',node.id);
                $('#flowerfq').attr('data-id',node.id);
                $('.name').attr('data-id',node.id);
                $('.cz').attr('data-id',node.id);
                $('.userId').html(node.id);
                $('.editmsg').attr('data-id',node.id);
                $('.editmsg').attr('data-username',node.name);
                $('.editmsg').attr('data-phone',node.phone);
                $('.editmsg').attr('data-name',node.logo);
                $('#transfer').attr('data-id',node.id);
                $('#transfer').attr('data-username',node.name);
                $('#server').attr('data-id',node.id);
                $('#server').attr('data-username',node.name);

                $('.pass_permission').attr('data-id', node.id);
                $('.agentincomworker').attr('data-id', node.id);

                }
                });

                var pid = parseInt(resultData[0].pid);

                if(pid < 2){
                $('.ceng').show()
                }else{
                $('.ceng').hide()
                }

                }else{
                    layer.msg('未查找到相关内容', {
                    offset: '50px'
                    ,icon: 2
                    ,time: 3000
                    });
                }
        })

        function mapTree  (value, arr)  {
            let newarr = [];
            arr.forEach(element => {
                if (element.name.indexOf(value) > -1) { // 判断条件
                    element['spread'] = true;
                    newarr.push(element);
                } else {
                if (element.children && element.children.length > 0) {
                    let redata = mapTree(value, element.children);
                    if (redata && redata.length > 0) {
                    let obj = {
                        ...element,
                        spread:true,
                        children: redata
                    };
                    newarr.push(obj);
                    }
                }
                }
            });
            return newarr;
        }

        $("#showAllAgent").click(function(){
          $('#demo').show()
          $('#searchlist').hide()
          $('#searchlist').html('')
          $('#showAllAgent').hide();
          $('#searchKey').val('')
          $('.name').html(treeData[0].name);
            $('.phone').html(treeData[0].phone);
            $('.jhm span').html(treeData[0].s_code);
            $('.jine span').html(treeData[0].money);
            $('.settlement_money span').html(treeData[0].settlement_money);
            $('#agent').attr('data-id',treeData[0].id);
            $('#role_fen').attr('data-id',treeData[0].id);
            $('#rate').attr('data-id',treeData[0].id);
            $('#server_rate').attr('data-id',treeData[0].id);
            $('#reward').attr('data-id',treeData[0].id);
            $('#putforward').attr('data-id',treeData[0].id);
            $('#storerate').attr('data-id',treeData[0].id);
            $('#storeconfig').attr('data-id',treeData[0].id);
            $('#chaxun').attr('data-id',treeData[0].id);
            $('#settle').attr('data-id',treeData[0].id);
            $('#flowerfq').attr('data-id',treeData[0].id);
            $('.name').attr('data-id',treeData[0].id);
            $('.userId').html(treeData[0].id);

            $('.editmsg').attr('data-id',treeData[0].id);
            $('.editmsg').attr('data-username',treeData[0].name);
            $('.editmsg').attr('data-phone',treeData[0].phone);
            $('.editmsg').attr('data-name',treeData[0].logo);

            $('#transfer').attr('data-id',treeData[0].id);
            $('#transfer').attr('data-username',treeData[0].name);
            $('.agentincomworker').attr('data-id', treeData[0].id);
            var pid = parseInt(treeData[0].pid);

            if(pid < 2){
                $('.ceng').show()
            }else{
                $('.ceng').hide()
            }
        });
        
        //员工管理
         $('.agentincomworker').click(function(){
            localStorage.setItem('agentName', $('.name').html());
            var user_id=$(this).attr('data-id');
            $('.agentincomworker').attr('lay-href',"{{url('/user/agentincomworker?')}}"+user_id);
        });
        
    });
</script>

</body>
</html>
